<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="../taglibs.jsp" %>
<script type="text/javascript">
	$(function() {
		$("#query").click(function() {
			var isSubmit = true;
			$("#productQueryForm").find("[reg]").each(function(){
				var val = $(this).val();
				val = $.trim(val);
				var tip = $(this).attr("tip");
				var regStr = $(this).attr("reg");
				var regObj = new RegExp(regStr);
				if(val != null && val != "" && !regObj.test(val)){
					isSubmit = false;
					Dialog.alert(tip);
					return false;
				}
			})
			
			if(isSubmit){
				$("form:first").submit();
			}
			
		});
	});
	
	function toAddProduct(){
		var diag = new Dialog();
		diag.Width = 850;
		diag.Height = 300;
		diag.Title = "添加商品";
		diag.URL = "${path}/product_input";
		diag.OKEvent = function(){
			//获得子页面的文档内容对象
			 var doc=diag.innerFrame.contentWindow;
			//alert(doc.age)
			var result = doc.submitAddProduct();
			if(result == "yes"){
				diag.close();
				window.location.href="${path}/product_list";
			}else{
				Dialog.alert("系统错误");
			}
			//diag.close();
			//window.location.href="${path}/emp_list";
		};
		diag.show();
	}
	
	function updateProduct(productId){
		var diag = new Dialog();
		diag.Width = 850;
		diag.Height = 300;
		diag.Title = "修改商品";
		diag.URL = "${path}/product_preupdate?productId="+productId;
		diag.OKEvent = function(){
			//获得子页面的文档内容对象
			 var doc=diag.innerFrame.contentWindow;
			//alert(doc.age)
			var result = doc.submitUpdateProduct();
			if(result == "yes"){
				diag.close();
				window.location.href="${path}/product_list";
			}else{
				Dialog.alert("系统错误");
			}
			//diag.close();
			//window.location.href="${path}/emp_list";
		};
		diag.show();
	}
	
</script>
<div class="content-right">
	<div class="content-r-pic_w">
		<div style="margin:8px auto auto 12px;margin-top:6px">
			<span class="page_title">商品管理</span>
		</div>
	</div>
	<div class="content-text">
		<form id="productQueryForm" action="${path }/product_list" method="post"> 
			<div class="square-o-top">
				<table width="100%" border="0" cellpadding="0" cellspacing="0"
					style="font-size:14px; font-weight:bold; font-family:"黑体";">
					<tr>
						<td>供应商:</td>
						<td>
							
							<s:select cssStyle="width:113px" list="#suppliers" name="erpQuery.supplierId" headerKey="" headerValue="--请选择--" listKey="supplierId" listValue="name"></s:select>
						</td>
						<td height="30">商&nbsp;品&nbsp;名</td>
						<td><s:textfield name="erpQuery.name" size="14"></s:textfield></td>
						<td>生产厂家</td>
						<td><s:textfield name="erpQuery.producer" size="14"></s:textfield></td>
						<td>单&nbsp;&nbsp;&nbsp;&nbsp;位</td>
						<td><s:textfield name="erpQuery.unit" size="14"></s:textfield></td>
						<td width="70"><a href="#" onclick="toAddProduct()" ><img src="${path}/images/can_b_02.gif" border="0" /> </a></td>
					</tr>
					<tr>
						<td height="30">进货价格</td>
						<td><s:textfield name="erpQuery.inPriceMin" size="14" reg="^[0-9]+(.[0-9]{2})?$" tip="进货价必须非0的正数"></s:textfield></td>
						<td>到</td>
						<td><s:textfield name="erpQuery.inPriceMax" size="14" reg="^[0-9]+(.[0-9]{2})?$" tip="进货价必须非0的正数"></s:textfield></td>
						<td height="30">销售价格</td>
						<td><s:textfield name="erpQuery.outPriceMin" size="14" reg="^[0-9]+(.[0-9]{2})?$" tip="销售价必须非0的正数"></s:textfield></td>
						<td>到</td>
						<td><s:textfield name="erpQuery.outPriceMax" size="14" reg="^[0-9]+(.[0-9]{2})?$" tip="销售价必须非0的正数"></s:textfield></td>
						<td><a id="query"> <img src="${path}/images/can_b_01.gif" border="0" /> </a></td>
					</tr>
				</table>
			</div>
			<!--"square-o-top"end-->
			<div class="square-order">
				<table width="100%" border="1" cellpadding="0" cellspacing="0">
					<tr align="center"
						style="background:url(${path}/images/table_bg.gif) repeat-x;">
						<td width="12%" height="30">供应商</td>
						<td width="12%">商品名</td>
						<td width="12%">生产厂家</td>
						<td width="12%">产地</td>
						<td width="12%">进货价格</td>
						<td width="12%">销售价格</td>
						<td width="12%">单位</td>
						<td width="16%">操作</td>
					</tr>
					
					<s:iterator value="#page.list" var="product">
						<tr align="center" bgcolor="#FFFFFF">
							<td width="13%" height="30"><s:property value="#product.productType.supplier.name"/></td>
							<td><s:property value="#product.name"/></td>
							<td><s:property value="#product.producer"/></td>
							<td><s:property value="#product.origin"/></td>
							<td align="right"><s:property value="#product.inPrice"/>&nbsp;元&nbsp;</td>
							<td align="right"><s:property value="#product.outPrice"/>&nbsp;元&nbsp;</td>
							<td><s:property value="#product.unit"/></td>
							<td>
								<img src="${path}/images/icon_3.gif" /> 
								<span style="line-height:12px; text-align:center;"> 
									<a href="#" onclick="updateProduct(<s:property value="#product.productId"/>)" class="xiu">修改</a> 
								</span> 
								<img src="${path}/images/icon_04.gif" /> 
								<span style="line-height:12px; text-align:center;"> 
									<a href="javascript:void(0)" class="xiu" onclick="showMsg('是否删除该项数据？',318)">删除</a>
								</span>
							</td>
						</tr>
					</s:iterator>
						
				</table>
				<%@include file="../tools/paging.jsp" %>
			</div>
		</form>
	</div>
	<div class="content-bbg"></div>
</div>
